package com.action.wx.wechat;

import com.common.BaseAction;
import com.common.ModelAndJson;
import com.util.Config;
import com.util.UploadUtil;
import com.util.wx.WXUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * Created by lvjianqing on 2017/10/7.
 */
@Controller
@RequestMapping("wx/wxjs")
public class WxJsApiAction extends BaseAction {

    /**
     * 下载微信图片，base64字符串
     *
     * @return
     */
    @RequestMapping("downloadImg")
    @ResponseBody
    public String wxDownLoadImage(HttpServletRequest request, String wxServerId) {
        String path = "-1";
        try {
            UploadUtil.writeFile(request, wxServerId + ".jpg", WXUtils.getMedia_ImgByte(wxServerId));
            path = Config.getString("domain") + "/upload/" + wxServerId + ".jpg";
        } catch (IOException e) {
            e.printStackTrace();
        }
        return path;
    }
}
